package com.zadtek.shopmall.other;

import android.content.Context;
import android.content.Intent;

import com.alibaba.mobileim.IYWLoginService;
import com.alibaba.mobileim.YWAPI;
import com.alibaba.mobileim.YWLoginParam;
import com.alibaba.mobileim.channel.event.IWxCallback;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXTextObject;
import com.zadtek.shopmall.App;
import com.zadtek.shopmall.activities.CarActivity;
import com.zadtek.shopmall.activities.ProductDetailActivity;
import com.zadtek.shopmall.activities.ProductListActivity;
import com.zadtek.shopmall.activities.ShopDetailActivity;
import com.zadtek.shopmall.activities.ShopListActivity;
import com.zadtek.shopmall.activities.TaskActivity;
import com.zadtek.shopmall.bean.HomeBaseBean;
import com.zadtek.shopmall.utils.SPUtil;
import com.zadtek.shopmall.utils.ToastUtil;

import static com.zadtek.shopmall.activities.ShopDetailActivity.SHOP_ID;

/**
 * Created by Zackv on 2018/5/3.
 */

public class Const {
    public static final String BASE_URL = "http://xmlife.zadtek.com/";
    public static final String SHARE_URL = BASE_URL+"mobile/index.php?m=user&a=affiliate";
    public static final String ABOUT_URL =  BASE_URL+"mobile/index.php?m=article&a=detail&id=61";
    public static final String USER_GUIDE_URL =  BASE_URL+"mobile/index.php?m=article&a=detail&id=10";
    public static final String PRIVACY_URL =  BASE_URL+"mobile/index.php?m=article&a=detail&id=2";



    public static final int PRODUCT = 0;
    public static final int SHOP = 1;
    public static final int NEWS = 2;
    public static final int PRODUCT_LIST = 3;
    public static final int SHOP_LIST = 4;
    public static final int CAR = 5;
    public static final int TASK = 6;
    public static final String UserName = "username";
    public static final String UserId = "userid";
    public static final String UserToken = "usertoken";
    public static final String Password = "password";
    public static final String IsLogin = "islogin";

    public static final String PACKGE_NAME = "com.zadtek.shopmall";
    public static boolean isLogin;
    public static int userid;
    public static String token = "";

    public static void jumpHandle(Context context, HomeBaseBean baseBean){
        ToastUtil.showToast(baseBean.getType()+" type" + baseBean.getId()+" id");
        switch (baseBean.getType()){
            case Const.NEWS:
                ToastUtil.showToast("新闻界面还没做！");
                //context.startActivity(new Intent(context, TaskActivity.class));
                WXTextObject textObj = new WXTextObject();
                textObj.text = "微信文本分享测试";
                // 用WXTextObject对象初始化一个WXMediaMessage对象
                WXMediaMessage msg = new WXMediaMessage();
                msg.mediaObject = textObj;   // 发送文本类型的消息时，title字段不起作用
                // msg.title = "Will be ignored";
                msg.description = "微信文本分享测试";   // 构造一个Req
                SendMessageToWX.Req req = new SendMessageToWX.Req();
                req.transaction = String.valueOf(System.currentTimeMillis()); // transaction字段用于唯一标识一个请求
                req.message = msg;   // 分享或收藏的目标场景，通过修改scene场景值实现。
                // 发送到聊天界面 —— WXSceneSession
                // 发送到朋友圈 —— WXSceneTimeline
                // 添加到微信收藏 —— WXSceneFavorite
                req.scene = SendMessageToWX.Req.WXSceneTimeline;
                // 调用api接口发送数据到微信
                App.iwxapi.sendReq(req);
                break;
            case Const.SHOP_LIST:
                ToastUtil.showToast("跳转到商铺列表");
                context.startActivity(new Intent(context, ShopListActivity.class));
                break;
            case Const.PRODUCT_LIST:
                ToastUtil.showToast("跳转到商品列表"+baseBean.getId());
                context.startActivity(new Intent(context, ProductListActivity.class));
                break;
            case Const.SHOP:
                ToastUtil.showToast("跳转到商店详情");
                context.startActivity(new Intent(context, ShopDetailActivity.class).putExtra(SHOP_ID,baseBean.getId()));
                break;
            case Const.PRODUCT:
                ToastUtil.showToast("跳转到商品详情");
                context.startActivity(new Intent(context, ProductDetailActivity.class));
                break;
            case Const.CAR:
                context.startActivity(new Intent(context, CarActivity.class));
                break;
            case Const.TASK:
                context.startActivity(new Intent(context, TaskActivity.class));
                break;
    }
    }


    public static void loginYM(){
        String userid = "testpro1";
        String password = "taobao1234";
        App.mIMKit = YWAPI.getIMKitInstance(userid, "23015524");
        IYWLoginService loginService = App.mIMKit.getLoginService();
        YWLoginParam loginParam = YWLoginParam.createLoginParam(userid, password);
        loginService.login(loginParam, new IWxCallback() {
            @Override
            public void onSuccess(Object... arg0) {

            }

            @Override
            public void onProgress(int arg0) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onError(int errCode, String description) {
                //如果登录失败，errCode为错误码,description是错误的具体描述信息
            }
        });
    }

    public static void init(Context context) {
        isLogin = (boolean) SPUtil.getData(context, IsLogin,false);
        if(isLogin){
            userid = (int) SPUtil.getData(context,UserId,-1);
            token = (String) SPUtil.getData(context,UserToken,"");
        }
    }
}
